package com.xyq;

import org.junit.jupiter.api.Test;

import java.util.Comparator;
import java.util.HashMap;
import java.util.TreeMap;

public class TreeMapDemo {
    public static void main(String[] args) {
        test2();
    }

    public static void test2() {
        TreeMap<Student, String> treeMap = new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return  o1.getAge() - o2.getAge();
            }
        });
        treeMap.put(new Student("张三", 20), "上海");
        treeMap.put(new Student("李四", 21), "北京");
        treeMap.put(new Student("王五", 22), "广州");
        treeMap.put(new Student("赵六", 23), "深圳");
        treeMap.forEach((k, v) -> System.out.println(k + ":" + v));

    }
    @Test
   private static void test1() {
        TreeMap<Student, String> treeMap = new TreeMap<>();

        treeMap.put(new Student("张三", 20), "上海");
        treeMap.put(new Student("李四", 21), "北京");
        treeMap.put(new Student("王五", 22), "广州");
        treeMap.put(new Student("赵六", 23), "深圳");
        treeMap.put(new Student("孙七", 24), "杭州");
        treeMap.put(new Student("周八", 25), "南京");
        treeMap.forEach((k, v) -> System.out.println(k + ":" + v));

        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("张三", "上海");

    }
}
